package com.subaiqiao.yunshiyuan.entrance.ysy.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.subaiqiao.yunshiyuan.basis.utils.Result;
import com.subaiqiao.yunshiyuan.entrance.ysy.service.FileValueService;
import com.subaiqiao.yunshiyuan.entrance.ysy.vo.FileValueVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author 曹朝禹
 * @since 2022-05-13
 */
@RestController
@RequestMapping("/ysy/fileValue")
@Api(tags = "文件信息")
public class FileValueController {

    @Autowired
    private FileValueService filevalueService;

    @ApiOperation("查询文件信息")
    @GetMapping("/FindFileValuePage.do")
    public Result FindFileValuePage(
            @RequestParam @ApiParam("页码") Integer pageNum,
            @RequestParam @ApiParam("数量") Integer pageSize,
            @RequestParam(defaultValue = "") @ApiParam("文件名称") String fileName,
            @RequestParam(defaultValue = "") @ApiParam("文件类型") Integer fileType
    ) {
        try {
            QueryWrapper<FileValueVO> wrapper = new QueryWrapper<>();
            wrapper.like("file_name", fileName)
                    .orderByDesc("create_datetime");
            if (fileType != null) {
                wrapper.eq("file_type", fileType);
            }
            return Result.success(filevalueService.FindFileValueVOPage(new Page<>(pageNum, pageSize), wrapper));
        } catch (Exception e) {
            return Result.error(e.getMessage());
        }
    }


    @ApiOperation("查询文件详情")
    @GetMapping("/FindFileValueDetail.do")
    public Result FindFileValueDetail(@RequestParam @ApiParam("文件编号") Integer fileId) {
        try {
            return Result.success(filevalueService.getById(fileId));
        } catch (Exception e) {
            return Result.error(e.getMessage());
        }
    }

    @ApiOperation("查询文件总数量")
    @GetMapping("/FindFileValueCount.do")
    public Result FindFileValueCount() {
        try {
            return Result.success(filevalueService.FindFileValueCount());
        } catch (Exception e) {
            return Result.error(e.getMessage());
        }
    }

    @ApiOperation("查询昨日上传文件总数")
    @GetMapping("/FindFileValueYesterdayRegister.do")
    public Result FindFileValueYesterdayRegister() {
        try {
            return Result.success(filevalueService.FindFileValueYesterdayRegister());
        } catch (Exception e) {
            return Result.error(e.getMessage());
        }
    }

}
